/*
 *------------------------------------------------------------------------------
 * @File      :    ili9488_mipi.c
 * @Date      :    2021-3-20
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Source file for MDP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */
#include "ei_comm_panel.h"
#include <fcntl.h>
#include "panel_usr.h"
#include "ei_math.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

#define ILI9488_HBP             (10)
#define ILI9488_HFP             (10)
#define ILI9488_HSW             (10)
#define ILI9488_HACT            (320)
#define ILI9488_HT              (ILI9488_HBP + ILI9488_HFP + ILI9488_HSW + ILI9488_HACT)
#define ILI9488_VBP             (10)
#define ILI9488_VFP             (10)
#define ILI9488_VSW             (10)
#define ILI9488_VACT            (480)
#define ILI9488_VT              (ILI9488_VBP + ILI9488_VFP + ILI9488_VSW + ILI9488_VACT)
#define ILI9488_PCLK            (18562500 / 1000)

static VO_PUB_ATTR_S ili9488_config = {
    .enIntfType = VO_INTF_MIPI,
    .enIntfSync = VO_OUTPUT_USER,
    .BufferSmooth = (-1U),

    .stSyncInfo.lane_id = {0,  -1,  -1,  -1},
    .stSyncInfo.output_mode = OUTPUT_MODE_DSI_CMD,
    .stSyncInfo.output_format = OUT_FORMAT_RGB_24_BIT,
    .stSyncInfo.video_mode =  NON_BURST_MODE_SYNC_EVENTS,
    .stSyncInfo.bIop = 1,
    .stSyncInfo.u16Hfb = ILI9488_HFP,
    .stSyncInfo.u16Hpw = ILI9488_HSW,
    .stSyncInfo.u16Hbb = ILI9488_HBP,
    .stSyncInfo.u16Hact = ILI9488_HACT,
    .stSyncInfo.u16Vfb = ILI9488_VFP,
    .stSyncInfo.u16Vpw = ILI9488_VSW,
    .stSyncInfo.u16Vbb = ILI9488_VBP,
    .stSyncInfo.u16Vact = ILI9488_VACT,
    .stSyncInfo.u32Pclk = ILI9488_PCLK, /* 59.4 kHz */
};

static unsigned char ili9488_init_code[] = {
    16, 0xE0, 0x00, 0x07, 0x10, 0x09, 0x17, 0x0B, 0x41, 0x89, 0x4B, 0x0A, 0x0C, 0x0E, 0x18, 0x1B, 0x0F,
    16, 0xE1, 0x00, 0x17, 0x1A, 0x04, 0x0E, 0x06, 0x2F, 0x45, 0x43, 0x02, 0x0A, 0x09, 0x32, 0x36, 0x0F,
    3, 0xC0, 0x17, 0x15,
    2, 0xC1, 0x41,
    4, 0xC5, 0x00, 0x20, 0x80,
    2, 0x36, 0x48,
    2, 0x3A, 0x66,
    2, 0xB0, 0x00,
    2, 0xB1, 0xA0,
    2, 0xB4, 0x02,
    3, 0xB6, 0x02, 0x02,
    2, 0xE9, 0x00,
    5, 0xF7, 0xA9, 0x51, 0x2C, 0x82,
    3, 0xF8, 0x21, 0x05,
    2, 0x11, 0x00,
    0, 100,
    2, 0x29, 0x00,
    0, 100,
};

EI_S32 panel_ili9488_get_panel_attr(PANEL_TYPE_E enPanelType,  PANEL_TYPE_ATTR_S *pstPanelAttr)
{
    pstPanelAttr->stVoPubAttr = ili9488_config;

    return EI_SUCCESS;
}

EI_S32 panel_ili9488_get_panel_init_code(PANEL_TYPE_E enPanelType,  PANEL_INIT_CODE_TYPE *init,  EI_U32 *pLen)
{
    *init = &ili9488_init_code[0];
    *pLen = EI_ARRAY_SIZE(ili9488_init_code);
    return EI_SUCCESS;
}

PANEL_OBJ_S stPanelIli9488Obj = {
    .pfnGetPanelAttrByPanel = panel_ili9488_get_panel_attr,
    .pfnGetPanelInitCodeByPanel = panel_ili9488_get_panel_init_code,
};

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

